package com.qisu.converters;

import java.util.Arrays;

import org.springframework.stereotype.Component;

import com.qisu.util.ByteArrayUtils;

/**
 *
 * @author alsan
 *
 */
@Component
public final class HexConverter implements FieldConverter<String> {

	@Override
	public String converter(byte[] data, int pos, int len) {
		if(null != data && data.length > 0) {
			return ByteArrayUtils.hexString(Arrays.copyOfRange(data, pos, pos + len));
		}
		return null;
	}

	@Override
	public String converter(byte[] data) {
		return converter(data, 0, data.length);
	}

}
